const Actions = require('./actions');
const DB = require('app/db');
import { monStorage, Storage } from 'clientConfig/util/StoreData';
import urllist from 'clientConfig/urllist';
import { Control } from 'react-keeper';
import net from 'clientConfig/util/net';
module.exports = Reflux.createStore({
    listenables: [Actions],
    data: {

    },

    onCheck: function (params, cb) {
        let t = this;
        let lists = [];
        let keys = ["headimg", "name", "nickname", "tel", "intuid", "sex", "birthday", "location", "corp", "email"];
        let titles = ['头像', '姓名', '昵称', '手机号', '云途号', '性别', '生日', '地区', '所在单位', '邮箱'];
        let result = params.result;
        // debugger
        let type = window.type;
        //  type='bp'
        for (let i in titles) {
            let obj = {};
            obj.title = titles[i];
            obj.keys = keys[i];
            if (i == 0) {
                obj.content = result.user[keys[i]] == '' ? (!result[type][keys[i]] ? result[type]["avatar"] : result[type][keys[i]]) : result.user[keys[i]];
            } else if (i == 8) {
                obj.content = result.user[keys[i]] == '' ? (!result[type][keys[i]] ? result[type]["corp_name"] : result[type][keys[i]]) : result.user[keys[i]];
            } else {
                obj.content = result.user[keys[i]] == '' ? (result[type][keys[i]] == '' ? "未设置" : result[type][keys[i]]) : result.user[keys[i]];
            }
            lists.push(obj);
        }
        let session = monStorage.get('user.session');
        if (type == 'bp') {
            lists[1].content = result[type].bpUserID;
            lists[8].content = '业务基础平台'
        }
        // debugger
        let id = Storage.get('user.id');
        let url = urllist.bindUserInfo + '?session=' + session + '&id=' + id;
        let bind_info = {
            tel: lists[3].content,//手机号
            name: lists[1].content,//姓名
            corp_name: lists[8].content,//单位
            role: params.result.role.text//角色
        }
        params.result.role = { text: bind_info };
        net.fetchUrl(url, { method: 'post', body: bind_info }).then((jsondata) => {
            if (!jsondata) return;
            if (jsondata.errcode == 0) {
                Control.go('/home', params)
            }
        });
    },

    updateComponent: function () {
        this.trigger(this.data);
    }
});
